package cc.customer.web.conversation;

import cc.customer.Conversation.ConversationService;
import cc.customer.bigEmport.damain.BigEmp;
import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.common.utils.FileUtils;
import cc.customer.myCustomer.damain.CusResource;
import cc.customer.rabbit.domain.CconvNotice;
import cc.customer.system.domain.MyUser;
import cc.customer.web.sys.controller.base.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value="conversation")
public class ConversationController extends BaseController {

   private Logger logger = LoggerFactory.getLogger(ConversationController.class);

   @Autowired
   private ConversationService converService;

   @RequestMapping(value="loadMonthRecordDetail")
   public String loadMonthRecordDetail(){return "customer/conversation/conversation_monthDetail";}

   @RequestMapping(value="loadNoticeDetail")
   public String loadNoticeDetail(){return "customer/conversation/conversation_noticeDetail";}

   /**查我的消息**/
   @RequestMapping(value="loadMyNotice")
   @ResponseBody
   public ResponseBo selectMyNotice(){
      MyUser user = this.getCurrentUser();
      return converService.selectMyNotice(user);
   }

   /**操作同意或拒绝共享*/
   @RequestMapping(value="updateShare")
   @ResponseBody
   public ResponseBo updateShare(String uuid,String data,String session,String cid){
      if(StringUtils.isAnyEmpty(uuid,data,session,cid)){
         return ResponseBo.error();
      }
      MyUser user = this.getCurrentUser();
      return converService.updateShare(uuid,data,session,cid,user);
   }

   /**选择通知的类型*/
   @RequestMapping(value="chooseNoticeType")
   @ResponseBody
   public ResponseBo chooseNoticeType(String type){
      if(StringUtils.isAnyEmpty(type)){ return ResponseBo.error(); }
      String username = this.getCurrentUser().getUsername();
      return converService.selectNoticeByType(username,type);
   }
   /**加载月报详情*/
   @RequestMapping(value="getRecordDetail")
   @ResponseBody
   public ResponseBo getRecordDetail(CconvNotice notice){
      if(StringUtils.isEmpty(notice.getcConvSession())){ return ResponseBo.error("获取数据失败，请联系网站管理员。"); }
      return converService.selectMonthRecord(notice);
   }
   /**加载通知详情*/
   @RequestMapping(value="getNoticeDetail")
   @ResponseBody
   public List<CconvNotice> selectNoticeDetail(CconvNotice notice){
       return this.converService.selectNoticeDetail(notice);
   }
   /**导出会话通知的信息**/
   @RequestMapping(value="exportSessionData")
   @ResponseBody
   public ResponseBo exportSessionData(String ids){
      if (StringUtils.isEmpty(ids)){ return ResponseBo.error("获取的用户数据失败"); }
      try {
         List<CusResource> list = converService.exportSessionData(ids);
         return FileUtils.createExcelByPOIKit("客户资料表", list, CusResource.class);
      }catch (Exception e){
         logger.error("会话资源导出客户失败："+e.getMessage());
      }
      return ResponseBo.error("导出失败");
   }
}
